package com.bw.mvpcore.view

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.bw.mvpcore.common.ConstValue

abstract class BaseActivity:AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(getLayoutId())
        initData(savedInstanceState)
        initEvent()
        if (isClearStatBar()){
            ClearStatBar()
        }
    }
    /**
     * 跳转到另一个Activity
     */
    fun jumpActivity(otherActivity:Class<*>){
        startActivity(Intent(this@BaseActivity,otherActivity))
    }
    fun jumpActivity(otherActivity:Class<*>,bundle:Bundle?){
        val intent = Intent(this@BaseActivity,otherActivity)
        intent.putExtra(ConstValue.JUMP_ACTIVITY_PARSENTER_KEY,bundle)
        startActivity(intent)
    }
    /**
     * 吐司显示消息
     */
    fun showToast(mag:String){
        Toast.makeText(this@BaseActivity, mag, Toast.LENGTH_SHORT).show()
    }

    /**
     * 沉浸式布局
     */
    abstract fun ClearStatBar()
    /**
     * 是否实现沉浸式
     */
    protected open  fun isClearStatBar(): Boolean{
        return true
    }

    /**
     * 初始化
     */
    abstract fun initEvent()
    /**
     * 初始化数据
     */
    abstract fun initData(savedInstanceState: Bundle?)
    /**
     * 获取布局
     */
    abstract fun getLayoutId(): Int

    override fun onStop() {
        super.onStop()
        releaseResource()
    }
    /**
     * 释放资源
     */
    abstract fun releaseResource()
}